<?php

namespace App\Admin\Controllers;

use App\Models\ActionLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ActionLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ActionLog(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('ip');
            $grid->column('url')->limit(60);
            $grid->column('param','请求参数');
            $grid->column('created_at','访问时间')->sortable();

            $grid->disableActions();
            $grid->disableCreateButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('ip','IP地址');
                $filter->like('url','访问地址');
                $filter->date('date','日期');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ActionLog(), function (Show $show) {
            $show->field('id');
            $show->field('ip');
            $show->field('url');
            $show->field('province');
            $show->field('city');
            $show->field('area');
            $show->field('date');
            $show->field('created_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ActionLog(), function (Form $form) {
            $form->display('id');
            $form->text('ip');
            $form->text('url');
            $form->text('province');
            $form->text('city');
            $form->text('area');
            $form->text('date');
            $form->text('created_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
